<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <title>删除数组所有重复项</title>
</head>

<body>
  <script>
    let arr = [1, 1, 2, 2, 3, 5, 5, 8, 8, 8, 8, 9];
    function removeAll() {
      const result = [];
      for (let i = 0; i < arr.length; i++) {
        /*如果数组arr的最后一个元素 完全等于
           循环里面的元素,就单一挑出来, push到一个新数组中并返回
          */
        if (arr.lastIndexOf(arr[i]) === i && arr.indexOf(arr[i]) === i) {
          result.push(arr[i]);
        }
      }
      return result;
    }
    const res = removeAll(arr);
    console.log(res);
  </script>
</body>

</html>